package cn.hd.controller;


import cn.hd.entity.*;
import cn.hd.service.ReturnService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@CrossOrigin
public class ReturnControl {
    @Autowired
    private ReturnService returnService;

    @RequestMapping("/addReturn")
    public Object addReturn(Returnn returnn){
//        Productdetail productdetail = returnService.selectproductid();
//        returnn.setPid(productdetail.getPid());
        int i = returnService.addReturn(returnn);
        if(i!=0){
            return new Result("200","添加成功",null);
        }else{
            return new Result("400","添加失败",null);
        }
    }

    @RequestMapping("/updateReturn")
    public Object updateReturn(Returnn returnn){
        int i=returnService.updateReturn(returnn);
        if (i!=0){
            return new Result("200","修改成功",null);
        }
        return  new Result("400","修改失败",null);
    }

    @RequestMapping("/delReturnn")
    public Object delReturnn(long returnid){
        int i = returnService.delReturnn(returnid);
        if(i!=0){
            return new Result("200","删除成功",null);
        }
        return new Result("400","删除失败",null);
    }

    @RequestMapping("/selectByIdReturn")
    public Object selectByIdReturn(long returnid){
        Returnn returnn = returnService.selectByIdReturn(returnid);
        return new Result("200","查询成功",returnn);
    }

    @RequestMapping("/selectReturn")
    public Object selectReturn(long pid){
//        PageInfo<Returnn> page = returnService.selectReturn(pagenum, pagesize,pid);
        List<Returnn> list = returnService.selectReturn(pid);
        if (list.size()==0){
            return new Result("400","查询失败",null);
        }
        return new Result("200","查询成功",list);
    }
    @RequestMapping("/selectReturnByPid")
    public Object selectReturnByPid(String pid){
        int p = Integer.parseInt(pid);
        List<Returnn> returnns = returnService.selectReturnById(p);
        if (returnns.size()==0){
            return new Result("400","查询失败",null);
        }
        return new Result("200","查询成功",returnns);
    }
}
